package com.tandashi.springbootstudy01.controller;

import com.tandashi.springbootstudy01.entity.master.SourceDataTmp;
import com.tandashi.springbootstudy01.entity.test.SourceData;
import com.tandashi.springbootstudy01.entity.user.LoginUser;
import com.tandashi.springbootstudy01.intercept.CostTime;
import com.tandashi.springbootstudy01.service.SourceDataService;
import com.tandashi.springbootstudy01.service.SourceDataTmpService;
import com.tandashi.springbootstudy01.util.JWTUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {

    @Autowired
    private SourceDataTmpService sourceDataTmpService;

    @Autowired
    private SourceDataService sourceDataService;


    @GetMapping("/noauth/costTime")
    @CostTime
    public String costTime(LoginUser user) throws InterruptedException {
        Thread.sleep(200);
        return "OK";
    }

    @GetMapping("/noauth/getToken")
    public String getToken(LoginUser user){
        String token = JWTUtils.encode(user);
        System.out.println("token: "+token);
        return token;
    }

    @GetMapping("/testA/{id}")
    public SourceDataTmp testA(@PathVariable Long id , @RequestAttribute String customerId){
        System.out.println("attribute customerId:"+customerId);
        return sourceDataTmpService.testA(id);
    }

    @GetMapping("/testB/{id}")
    public SourceData testB(@PathVariable Long id){
        return sourceDataService.testB(id);
    }


    @GetMapping("/test/myBatis")
    public String testMyBatis(){
        SourceDataTmp tmp = sourceDataTmpService.queryById(1L);
        System.out.println("tmp:"+tmp);
        SourceDataTmp tmp1 = sourceDataTmpService.queryById(1L);
        System.out.println("tmp1:"+tmp1);
        return "OK";
    }

    @GetMapping("/hello")
    public String say(){
        return "Hello SpringBoot";
    }

    @GetMapping("/v1")
    public String branch(){
        return "I am feature-v1";
    }

    @GetMapping("/v2")
    public String branch2(){
        return "I am feature-v2";
    }

    //v3加点注释来看看
    @GetMapping("/v3")
    public String branch3(){
        return "I am feature-v3";
    }

    @GetMapping("/v4")
    public String branch4(){
        return "I am feature-v4";
    }

    @GetMapping("/test-merge")
    public String testMerge(){
        return "test-merge";
    }
}
